﻿/**
 * Jean-François Desgagné 2009 Portfolio
 * Copyright (c) 2009 Jean-François Desgagné <jfesgagne@gmail.com>
 * 
 * This work is licensed under a Creative Commons Attribution 3.0 United States License.
 * Some Rights Reserved.
 */
package com.jfdesgagne.jfdesgagne09.shell.model {
     import com.jfdesgagne.jfdesgagne09.shell.ApplicationFacade;
    
    import flash.events.Event;
    import flash.net.URLLoader;
    import flash.net.URLRequest;
	import fl.lang.Locale;
	
    
    import org.puremvc.as3.multicore.interfaces.IProxy;
    import org.puremvc.as3.multicore.patterns.proxy.Proxy;

    public class LocaleProxy extends Proxy implements IProxy {
        public static const NAME:String = "LocaleProxy";
		
        public function LocaleProxy() {
			super(NAME, new Object());
        }
		
		override public function onRegister():void {
			var http_address:String = ConfigProxy(this.facade.retrieveProxy(ConfigProxy.NAME)).parameters.http_address;
			Locale.addXMLPath("en", http_address+"system/locale/en/jfdesgagne09_en.xml");
			Locale.addXMLPath("fr", http_address+"system/locale/fr/jfdesgagne09_fr.xml");
			Locale.setDefaultLang("en");
			Locale.setLoadCallback(this._localeLoadCompleteHandler);
			Locale.loadLanguageXML(Locale.getDefaultLang());
		}
		
		private function _localeLoadCompleteHandler(success:Boolean):void {
			if (success) {
				sendNotification(ApplicationFacade.LOCALPROXY_LOADED);
			} else {
				trace("ERROR LOADING Locale " + Locale.getDefaultLang());
			}
		}
		
		public static function get lang():String {
			return Locale.getDefaultLang();
		}
		
		public static function getInstance():ConfigProxy {
			return ApplicationFacade.getInstance(ApplicationFacade.NAME).retrieveProxy( ConfigProxy.NAME ) as ConfigProxy;
		}
		
		public static function getString($key:String):String {
			return Locale.loadString($key);
		}
    }
}